import lombok.AllArgsConstructor;
import lombok.Data;
import org.zjx.core.DecisionContext;
import org.zjx.core.DecisionNode;
import org.zjx.core.GameAction;
import org.zjx.core.state.StateAccessor;

import java.util.Map;
import java.util.function.BiPredicate;

@Data
@AllArgsConstructor
public class ConditionNode implements DecisionNode {
    private BiPredicate<StateAccessor, Map<String, Object>> condition;
    private DecisionNode trueBranch;
    private DecisionNode falseBranch;

    @Override
    public GameAction decide(DecisionContext context) {
        boolean result = condition.test(
                context.getStateAccessor(),
                context.getLocalParams()
        );
        DecisionNode next = result ? trueBranch : falseBranch;

        if (next != null) {
            // 直接执行下一个节点并返回其结果
            return next.decide(context);
        }
        return null; // 如果没有分支则返回null
    }
}